package ac.leedsmet.devmanager.guiApp;

import ac.leedsmet.devmanager.DevManagerView;
import ac.leedsmet.devmanager.core.Project;
import ac.leedsmet.devmanager.core.ProjectManagerImpl;

import javax.swing.*;
import java.awt.event.ActionEvent;
import java.awt.event.InputMethodEvent;
import java.awt.event.ItemEvent;
import java.awt.event.MouseEvent;
import java.util.ArrayList;
import ac.leedsmet.devmanager.core.Story;
import ac.leedsmet.devmanager.core.StoryManagerImpl;
import org.jdesktop.application.Application;
import org.jdesktop.application.ResourceMap;

/*
 * AgileRequirementsManagement.java
 *
 * Created on Nov 19, 2011, 2:54:38 PM
 * @author Mike
 * @author Samael
 * @author Takamura
 * @version 1.0
 */
public class AgileRequirementsManagement extends JInternalFrame {

    /**
     * A return status code - returned if Cancel button has been pressed
     */
    public static final int RET_CANCEL = 0;

    /**
     * A return status code - returned if OK button has been pressed
     */
    public static final int RET_OK = 1;

    private DevManagerView dmv;
    private ProjectManagerImpl pM = new ProjectManagerImpl();
    private StoryManagerImpl sM = new StoryManagerImpl(DevManagerView.getCurrentProject());
    private Story currentStory;

    /**
     * Class constructor.
     *
     * @param parent - DevManager application frame
     * @return AgileRequirementsManagement processing form.
     */
    public AgileRequirementsManagement(DevManagerView parent) {
        dmv = parent;
        initComponents();
        // UserStories_List.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
    }

    /**
     * This function sets the return status and closes the dialog.
     * @param retStatus The return status variable.
     */
    private void doClose(int retStatus) {
        returnStatus = retStatus;
        setVisible(false);
        dispose();
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        StoryBase_Panel = new javax.swing.JPanel();
        Story_Panel = new javax.swing.JPanel();
        Title_TextField = new javax.swing.JTextField();
        AsA_TextField = new javax.swing.JTextField();
        Assignee_Label = new javax.swing.JLabel();
        SoThat_Label = new javax.swing.JLabel();
        Effort_Label = new javax.swing.JLabel();
        Assignee_ComboBox = new javax.swing.JComboBox();
        Effort_TextField = new javax.swing.JTextField();
        AsA_Label = new javax.swing.JLabel();
        SoThat_ScrollPane = new javax.swing.JScrollPane();
        SoThat_TextArea = new javax.swing.JTextArea();
        IWant_Label = new javax.swing.JLabel();
        Title_Label = new javax.swing.JLabel();
        IWant_ScrollPane = new javax.swing.JScrollPane();
        IWant_TextArea = new javax.swing.JTextArea();
        Attachment_Label = new javax.swing.JLabel();
        Attachment_TextField = new javax.swing.JTextField();
        AttachmentBrowse_Button = new javax.swing.JButton();
        StoryButtons_Panel = new javax.swing.JPanel();
        StorySave_Button = new javax.swing.JButton();
        StoryCancel_Button = new javax.swing.JButton();
        UserStories_Panel = new javax.swing.JPanel();
        UserStories_ScrollPane = new javax.swing.JScrollPane();
        UserStories_List = new javax.swing.JList();
        UserStoriesButtons_Panel = new javax.swing.JPanel();
        UserStoriesMoveUp_Button = new javax.swing.JButton();
        UserStoriesMoveDown_Button = new javax.swing.JButton();
        UserStoriesEdit_Button = new javax.swing.JButton();
        UserStoriesDelete_Button = new javax.swing.JButton();
        StoryTitile_Label = new javax.swing.JLabel();
        AssigneeUserStories_Label = new javax.swing.JLabel();
        PercentComplete_Label = new javax.swing.JLabel();
        MainOK_Panel = new javax.swing.JPanel();
        AgileRequirementsOK_Button = new javax.swing.JButton();

        org.jdesktop.application.ResourceMap resourceMap = org.jdesktop.application.Application.getInstance(ac.leedsmet.devmanager.DevManagerApp.class).getContext().getResourceMap(AgileRequirementsManagement.class);
        setTitle(resourceMap.getString("Form.title")); // NOI18N
        setToolTipText(resourceMap.getString("Form.toolTipText")); // NOI18N
        setName("Form"); // NOI18N

        StoryBase_Panel.setBorder(javax.swing.BorderFactory.createEtchedBorder());
        StoryBase_Panel.setName("StoryBase_Panel"); // NOI18N

        Story_Panel.setBorder(javax.swing.BorderFactory.createTitledBorder(javax.swing.BorderFactory.createEtchedBorder(), resourceMap.getString("Story_jPanel.border.title"), javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, resourceMap.getFont("Story_jPanel.border.titleFont"))); // NOI18N
        Story_Panel.setName("Story_jPanel"); // NOI18N

        Title_TextField.setText(resourceMap.getString("Title_TextField.text")); // NOI18N
        Title_TextField.setName("Title_TextField"); // NOI18N
        Title_TextField.setNextFocusableComponent(AsA_TextField);
        Title_TextField.addInputMethodListener(new java.awt.event.InputMethodListener() {
            public void inputMethodTextChanged(java.awt.event.InputMethodEvent evt) {
                Title_TextFieldInputMethodTextChanged(evt);
            }
            public void caretPositionChanged(java.awt.event.InputMethodEvent evt) {
            }
        });

        AsA_TextField.setText(resourceMap.getString("AsA_TextField.text")); // NOI18N
        AsA_TextField.setName("AsA_TextField"); // NOI18N
        AsA_TextField.setNextFocusableComponent(IWant_TextArea);
        AsA_TextField.addInputMethodListener(new java.awt.event.InputMethodListener() {
            public void inputMethodTextChanged(java.awt.event.InputMethodEvent evt) {
                AsA_TextFieldInputMethodTextChanged(evt);
            }
            public void caretPositionChanged(java.awt.event.InputMethodEvent evt) {
            }
        });

        Assignee_Label.setText(resourceMap.getString("Assignee_Label.text")); // NOI18N
        Assignee_Label.setName("Assignee_Label"); // NOI18N

        SoThat_Label.setText(resourceMap.getString("SoThat_jLabel.text")); // NOI18N
        SoThat_Label.setName("SoThat_jLabel"); // NOI18N

        Effort_Label.setText(resourceMap.getString("Effort_jLabel.text")); // NOI18N
        Effort_Label.setName("Effort_jLabel"); // NOI18N

        Assignee_ComboBox.setModel(new javax.swing.DefaultComboBoxModel(new String[] { " ", "Mike Piazza", "Sam Bate", "Anthony Balis" }));
        Assignee_ComboBox.setName("Assignee_ComboBox"); // NOI18N
        Assignee_ComboBox.setNextFocusableComponent(Attachment_TextField);
        Assignee_ComboBox.setOpaque(false);
        Assignee_ComboBox.addItemListener(new java.awt.event.ItemListener() {
            public void itemStateChanged(java.awt.event.ItemEvent evt) {
                Assignee_ComboBoxItemStateChanged(evt);
            }
        });

        Effort_TextField.setHorizontalAlignment(javax.swing.JTextField.TRAILING);
        Effort_TextField.setText(resourceMap.getString("Effort_TextField.text")); // NOI18N
        Effort_TextField.setName("Effort_TextField"); // NOI18N
        Effort_TextField.setNextFocusableComponent(Assignee_ComboBox);
        Effort_TextField.addInputMethodListener(new java.awt.event.InputMethodListener() {
            public void inputMethodTextChanged(java.awt.event.InputMethodEvent evt) {
                Effort_TextFieldInputMethodTextChanged(evt);
            }
            public void caretPositionChanged(java.awt.event.InputMethodEvent evt) {
            }
        });

        AsA_Label.setText(resourceMap.getString("AsA_jLabel.text")); // NOI18N
        AsA_Label.setName("AsA_jLabel"); // NOI18N

        SoThat_ScrollPane.setName("SoThat_ScrollPane"); // NOI18N

        SoThat_TextArea.setColumns(20);
        SoThat_TextArea.setRows(5);
        SoThat_TextArea.setWrapStyleWord(true);
        SoThat_TextArea.setName("SoThat_TextArea"); // NOI18N
        SoThat_TextArea.setNextFocusableComponent(Effort_TextField);
        SoThat_TextArea.addInputMethodListener(new java.awt.event.InputMethodListener() {
            public void inputMethodTextChanged(java.awt.event.InputMethodEvent evt) {
                SoThat_TextAreaInputMethodTextChanged(evt);
            }
            public void caretPositionChanged(java.awt.event.InputMethodEvent evt) {
            }
        });
        SoThat_ScrollPane.setViewportView(SoThat_TextArea);

        IWant_Label.setText(resourceMap.getString("IWant_jLabel.text")); // NOI18N
        IWant_Label.setName("IWant_jLabel"); // NOI18N

        Title_Label.setText(resourceMap.getString("Title_jLabel.text")); // NOI18N
        Title_Label.setName("Title_jLabel"); // NOI18N

        IWant_ScrollPane.setName("IWant_ScrollPane"); // NOI18N

        IWant_TextArea.setColumns(20);
        IWant_TextArea.setRows(5);
        IWant_TextArea.setWrapStyleWord(true);
        IWant_TextArea.setName("IWant_TextArea"); // NOI18N
        IWant_TextArea.setNextFocusableComponent(SoThat_TextArea);
        IWant_TextArea.addInputMethodListener(new java.awt.event.InputMethodListener() {
            public void inputMethodTextChanged(java.awt.event.InputMethodEvent evt) {
                IWant_TextAreaInputMethodTextChanged(evt);
            }
            public void caretPositionChanged(java.awt.event.InputMethodEvent evt) {
            }
        });
        IWant_ScrollPane.setViewportView(IWant_TextArea);

        Attachment_Label.setText(resourceMap.getString("Attachment_jLabel.text")); // NOI18N
        Attachment_Label.setName("Attachment_jLabel"); // NOI18N

        Attachment_TextField.setText(resourceMap.getString("AttachmentFilename_jTextField.text")); // NOI18N
        Attachment_TextField.setName("AttachmentFilename_jTextField"); // NOI18N
        Attachment_TextField.setNextFocusableComponent(AttachmentBrowse_Button);

        AttachmentBrowse_Button.setText(resourceMap.getString("AttachmentBrowse_jButton.text")); // NOI18N
        AttachmentBrowse_Button.setName("AttachmentBrowse_jButton"); // NOI18N
        AttachmentBrowse_Button.setNextFocusableComponent(StorySave_Button);
        AttachmentBrowse_Button.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                AttachmentBrowse_ButtonActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout Story_PanelLayout = new javax.swing.GroupLayout(Story_Panel);
        Story_Panel.setLayout(Story_PanelLayout);
        Story_PanelLayout.setHorizontalGroup(
                Story_PanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addGroup(Story_PanelLayout.createSequentialGroup()
                                .addContainerGap()
                                .addGroup(Story_PanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                        .addComponent(Title_Label)
                                        .addComponent(AsA_Label)
                                        .addComponent(IWant_Label)
                                        .addComponent(SoThat_Label)
                                        .addComponent(Effort_Label)
                                        .addComponent(Attachment_Label))
                                .addGap(10, 10, 10)
                                .addGroup(Story_PanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                        .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, Story_PanelLayout.createSequentialGroup()
                                                .addComponent(Effort_TextField, javax.swing.GroupLayout.PREFERRED_SIZE, 78, javax.swing.GroupLayout.PREFERRED_SIZE)
                                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 76, Short.MAX_VALUE)
                                                .addComponent(Assignee_Label)
                                                .addGap(18, 18, 18)
                                                .addComponent(Assignee_ComboBox, javax.swing.GroupLayout.PREFERRED_SIZE, 169, javax.swing.GroupLayout.PREFERRED_SIZE))
                                        .addComponent(SoThat_ScrollPane, javax.swing.GroupLayout.DEFAULT_SIZE, 384, Short.MAX_VALUE)
                                        .addComponent(IWant_ScrollPane, javax.swing.GroupLayout.DEFAULT_SIZE, 384, Short.MAX_VALUE)
                                        .addComponent(AsA_TextField, javax.swing.GroupLayout.DEFAULT_SIZE, 384, Short.MAX_VALUE)
                                        .addComponent(Title_TextField, javax.swing.GroupLayout.DEFAULT_SIZE, 384, Short.MAX_VALUE)
                                        .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, Story_PanelLayout.createSequentialGroup()
                                                .addComponent(Attachment_TextField, javax.swing.GroupLayout.DEFAULT_SIZE, 299, Short.MAX_VALUE)
                                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                                .addComponent(AttachmentBrowse_Button)
                                                .addGap(8, 8, 8)))
                                .addContainerGap())
        );
        Story_PanelLayout.setVerticalGroup(
                Story_PanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addGroup(Story_PanelLayout.createSequentialGroup()
                                .addContainerGap()
                                .addGroup(Story_PanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                        .addComponent(Title_Label)
                                        .addComponent(Title_TextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                                .addGap(18, 18, 18)
                                .addGroup(Story_PanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                        .addComponent(AsA_Label)
                                        .addComponent(AsA_TextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                                .addGap(18, 18, 18)
                                .addGroup(Story_PanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                        .addComponent(IWant_ScrollPane, javax.swing.GroupLayout.PREFERRED_SIZE, 73, javax.swing.GroupLayout.PREFERRED_SIZE)
                                        .addComponent(IWant_Label))
                                .addGap(18, 18, 18)
                                .addGroup(Story_PanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                        .addComponent(SoThat_Label)
                                        .addComponent(SoThat_ScrollPane, javax.swing.GroupLayout.PREFERRED_SIZE, 77, javax.swing.GroupLayout.PREFERRED_SIZE))
                                .addGap(18, 18, 18)
                                .addGroup(Story_PanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                        .addComponent(Effort_TextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                        .addComponent(Effort_Label)
                                        .addComponent(Assignee_ComboBox, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                        .addComponent(Assignee_Label))
                                .addGap(18, 18, 18)
                                .addGroup(Story_PanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                        .addComponent(Attachment_Label)
                                        .addComponent(Attachment_TextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                        .addComponent(AttachmentBrowse_Button))
                                .addContainerGap(41, Short.MAX_VALUE))
        );

        StoryButtons_Panel.setBorder(javax.swing.BorderFactory.createEtchedBorder());
        StoryButtons_Panel.setName("StoryButtons_Panel"); // NOI18N

        StorySave_Button.setText(resourceMap.getString("StorySave_Button.text")); // NOI18N
        StorySave_Button.setName("StorySave_Button"); // NOI18N
        StorySave_Button.setNextFocusableComponent(StoryCancel_Button);
        StorySave_Button.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                StorySave_ButtonMouseClicked(evt);
            }
        });

        StoryCancel_Button.setText(resourceMap.getString("StoryCancel_Button.text")); // NOI18N
        StoryCancel_Button.setName("StoryCancel_Button"); // NOI18N
        StoryCancel_Button.setNextFocusableComponent(Title_TextField);
        StoryCancel_Button.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                StoryCancel_ButtonMouseClicked(evt);
            }
        });

        javax.swing.GroupLayout StoryButtons_PanelLayout = new GroupLayout(StoryButtons_Panel);
        StoryButtons_Panel.setLayout(StoryButtons_PanelLayout);
        StoryButtons_PanelLayout.setHorizontalGroup(
                StoryButtons_PanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING)
                        .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, StoryButtons_PanelLayout.createSequentialGroup()
                                .addContainerGap(300, Short.MAX_VALUE)
                                .addComponent(StorySave_Button, GroupLayout.PREFERRED_SIZE, 66, GroupLayout.PREFERRED_SIZE)
                                .addGap(18, 18, 18)
                                .addComponent(StoryCancel_Button)
                                .addGap(29, 29, 29))
        );
        StoryButtons_PanelLayout.setVerticalGroup(
                StoryButtons_PanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING)
                        .addGroup(StoryButtons_PanelLayout.createSequentialGroup()
                                .addContainerGap()
                                .addGroup(StoryButtons_PanelLayout.createParallelGroup(GroupLayout.Alignment.BASELINE)
                                        .addComponent(StoryCancel_Button)
                                        .addComponent(StorySave_Button))
                                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        javax.swing.GroupLayout StoryBase_PanelLayout = new javax.swing.GroupLayout(StoryBase_Panel);
        StoryBase_Panel.setLayout(StoryBase_PanelLayout);
        StoryBase_PanelLayout.setHorizontalGroup(
                StoryBase_PanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addGroup(StoryBase_PanelLayout.createSequentialGroup()
                                .addContainerGap()
                                .addGroup(StoryBase_PanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                        .addComponent(Story_Panel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                        .addComponent(StoryButtons_Panel, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                                .addContainerGap())
        );
        StoryBase_PanelLayout.setVerticalGroup(
                StoryBase_PanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, StoryBase_PanelLayout.createSequentialGroup()
                                .addContainerGap()
                                .addComponent(Story_Panel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(StoryButtons_Panel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addGap(11, 11, 11))
        );

        UserStories_Panel.setBorder(javax.swing.BorderFactory.createEtchedBorder());
        UserStories_Panel.setName("UserStories_Panel"); // NOI18N

        UserStories_ScrollPane.setBorder(javax.swing.BorderFactory.createTitledBorder(BorderFactory.createEtchedBorder(), resourceMap.getString("UserStories_jScrollPane.border.title"), javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, resourceMap.getFont("UserStories_jScrollPane.border.titleFont"))); // NOI18N
        UserStories_ScrollPane.setName("UserStories_jScrollPane"); // NOI18N
        UserStories_ScrollPane.setPreferredSize(new java.awt.Dimension(462, 151));

        UserStories_List.setName("UserStories_jList"); // NOI18N
        UserStories_List.setNextFocusableComponent(UserStoriesMoveUp_Button);
        UserStories_ScrollPane.setViewportView(UserStories_List);

        UserStoriesButtons_Panel.setBorder(javax.swing.BorderFactory.createEtchedBorder());
        UserStoriesButtons_Panel.setName("UserStoriesButtonPanel_jPanel"); // NOI18N
        UserStoriesButtons_Panel.setPreferredSize(new java.awt.Dimension(462, 49));

        UserStoriesMoveUp_Button.setText(resourceMap.getString("UserStoriesMoveUp_Button.text")); // NOI18N
        UserStoriesMoveUp_Button.setName("UserStoriesMoveUp_Button"); // NOI18N
        UserStoriesMoveUp_Button.setNextFocusableComponent(UserStoriesMoveDown_Button);
        UserStoriesMoveUp_Button.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                UserStoriesMoveUp_ButtonMouseClicked(evt);
            }
        });

        UserStoriesMoveDown_Button.setText(resourceMap.getString("UserStoriesMoveDown_Button.text")); // NOI18N
        UserStoriesMoveDown_Button.setName("UserStoriesMoveDown_Button"); // NOI18N
        UserStoriesMoveDown_Button.setNextFocusableComponent(UserStoriesEdit_Button);
        UserStoriesMoveDown_Button.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                UserStoriesMoveDown_ButtonMouseClicked(evt);
            }
        });

        UserStoriesEdit_Button.setText(resourceMap.getString("UserStoriesEdit_Button.text")); // NOI18N
        UserStoriesEdit_Button.setName("UserStoriesEdit_Button"); // NOI18N
        UserStoriesEdit_Button.setNextFocusableComponent(UserStoriesDelete_Button);
        UserStoriesEdit_Button.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                UserStoriesEdit_ButtonMouseClicked(evt);
            }
        });

        UserStoriesDelete_Button.setText(resourceMap.getString("UserStoriesDelete_Button.text")); // NOI18N
        UserStoriesDelete_Button.setName("UserStoriesDelete_Button"); // NOI18N
        UserStoriesDelete_Button.setNextFocusableComponent(AgileRequirementsOK_Button);
        UserStoriesDelete_Button.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                UserStoriesDelete_ButtonMouseClicked(evt);
            }
        });

        javax.swing.GroupLayout UserStoriesButtons_PanelLayout = new javax.swing.GroupLayout(UserStoriesButtons_Panel);
        UserStoriesButtons_Panel.setLayout(UserStoriesButtons_PanelLayout);
        UserStoriesButtons_PanelLayout.setHorizontalGroup(
                UserStoriesButtons_PanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addGroup(UserStoriesButtons_PanelLayout.createSequentialGroup()
                                .addGap(18, 18, 18)
                                .addComponent(UserStoriesMoveUp_Button, javax.swing.GroupLayout.PREFERRED_SIZE, 85, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addGap(18, 18, 18)
                                .addComponent(UserStoriesMoveDown_Button)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 81, Short.MAX_VALUE)
                                .addComponent(UserStoriesEdit_Button, javax.swing.GroupLayout.PREFERRED_SIZE, 67, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addGap(18, 18, 18)
                                .addComponent(UserStoriesDelete_Button)
                                .addGap(19, 19, 19))
        );
        UserStoriesButtons_PanelLayout.setVerticalGroup(
                UserStoriesButtons_PanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, UserStoriesButtons_PanelLayout.createSequentialGroup()
                                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                .addGroup(UserStoriesButtons_PanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                        .addComponent(UserStoriesMoveUp_Button)
                                        .addComponent(UserStoriesEdit_Button)
                                        .addComponent(UserStoriesDelete_Button)
                                        .addComponent(UserStoriesMoveDown_Button))
                                .addContainerGap())
        );

        StoryTitile_Label.setText(resourceMap.getString("StoryTitile_Label.text")); // NOI18N
        StoryTitile_Label.setName("StoryTitile_Label"); // NOI18N

        AssigneeUserStories_Label.setText(resourceMap.getString("AssigneeUserStories_Label.text")); // NOI18N
        AssigneeUserStories_Label.setName("AssigneeUserStories_Label"); // NOI18N

        PercentComplete_Label.setText(resourceMap.getString("PercentComplete_Label.text")); // NOI18N
        PercentComplete_Label.setEnabled(false);
        PercentComplete_Label.setName("PercentComplete_Label"); // NOI18N

        javax.swing.GroupLayout UserStories_PanelLayout = new javax.swing.GroupLayout(UserStories_Panel);
        UserStories_Panel.setLayout(UserStories_PanelLayout);
        UserStories_PanelLayout.setHorizontalGroup(
                UserStories_PanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, UserStories_PanelLayout.createSequentialGroup()
                                .addGap(45, 45, 45)
                                .addComponent(StoryTitile_Label)
                                .addGap(102, 102, 102)
                                .addComponent(AssigneeUserStories_Label)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 195, Short.MAX_VALUE)
                                .addComponent(PercentComplete_Label)
                                .addGap(48, 48, 48))
                        .addGroup(UserStories_PanelLayout.createSequentialGroup()
                                .addContainerGap()
                                .addGroup(UserStories_PanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                        .addComponent(UserStories_ScrollPane, javax.swing.GroupLayout.PREFERRED_SIZE, 462, javax.swing.GroupLayout.PREFERRED_SIZE)
                                        .addComponent(UserStoriesButtons_Panel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        UserStories_PanelLayout.setVerticalGroup(
                UserStories_PanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addGroup(UserStories_PanelLayout.createSequentialGroup()
                                .addContainerGap()
                                .addGroup(UserStories_PanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                        .addComponent(PercentComplete_Label)
                                        .addComponent(StoryTitile_Label)
                                        .addComponent(AssigneeUserStories_Label))
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(UserStories_ScrollPane, javax.swing.GroupLayout.PREFERRED_SIZE, 183, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(UserStoriesButtons_Panel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        MainOK_Panel.setBorder(javax.swing.BorderFactory.createEtchedBorder());
        MainOK_Panel.setName("MainOK_Panel"); // NOI18N

        AgileRequirementsOK_Button.setText(resourceMap.getString("AgileRequirementsOK_Button.text")); // NOI18N
        AgileRequirementsOK_Button.setName("AgileRequirementsOK_Button"); // NOI18N
        AgileRequirementsOK_Button.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                AgileRequirementsOK_ButtonActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout MainOK_PanelLayout = new javax.swing.GroupLayout(MainOK_Panel);
        MainOK_Panel.setLayout(MainOK_PanelLayout);
        MainOK_PanelLayout.setHorizontalGroup(
                MainOK_PanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, MainOK_PanelLayout.createSequentialGroup()
                                .addContainerGap(372, Short.MAX_VALUE)
                                .addComponent(AgileRequirementsOK_Button, javax.swing.GroupLayout.PREFERRED_SIZE, 73, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addGap(37, 37, 37))
        );
        MainOK_PanelLayout.setVerticalGroup(
                MainOK_PanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addGroup(MainOK_PanelLayout.createSequentialGroup()
                                .addContainerGap()
                                .addComponent(AgileRequirementsOK_Button)
                                .addContainerGap(15, Short.MAX_VALUE))
        );

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
                layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addComponent(StoryBase_Panel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                                .addContainerGap()
                                .addComponent(UserStories_Panel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                .addContainerGap())
                        .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                                .addContainerGap()
                                .addComponent(MainOK_Panel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                .addContainerGap())
        );
        layout.setVerticalGroup(
                layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                                .addComponent(StoryBase_Panel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(UserStories_Panel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(MainOK_Panel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addContainerGap())
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    /**
     * @param evt
     */
    private void Title_TextFieldInputMethodTextChanged(InputMethodEvent evt) {
        currentStory.setTitle(Title_TextField.getText());
    }

    /**
     * @param evt
     */
    private void AsA_TextFieldInputMethodTextChanged(InputMethodEvent evt) {
        currentStory.setAsA(AsA_TextField.getText());
    }

    /**
     * @param
     */
    private void IWant_TextAreaInputMethodTextChanged(InputMethodEvent evt) {
        currentStory.setIWant(IWant_TextArea.getText());
    }//GEN-LAST:event_IWant_TextAreaInputMethodTextChanged

    /**
     * @param evt
     */
    private void SoThat_TextAreaInputMethodTextChanged(InputMethodEvent evt) {
        currentStory.setSoThat(SoThat_TextArea.getText());
    }

    /**
     * @param
     */
    private void Effort_TextFieldInputMethodTextChanged(InputMethodEvent evt) {
//    currentStory.setEffort(Effort_TextField.getBytes(Effort_TextField.getText()));
        currentStory.setEffort(Effort_TextField.getText());
    }

    /**
     * @param evt The event that triggered the...
     */
    private void Assignee_ComboBoxItemStateChanged(ItemEvent evt) {
        currentStory.setAssignee((String)Assignee_ComboBox.getSelectedItem());
    }

    /**
     * This function clears the forms text fields and sets them to null strings.
     */
    private void clearStory() {
        Title_TextField.setText("");
        AsA_TextField.setText("");
        IWant_TextArea.setText("");
        SoThat_TextArea.setText("");
        Effort_TextField.setText("");
        Assignee_ComboBox.setSelectedItem(0);
        Attachment_TextField.setText("");
    }

    /**
     * @param evt
     */
    private void StorySave_ButtonMouseClicked(MouseEvent evt) {
        // Update the current Story with the data in the form's text fields.
        currentStory = sM.createStory(Title_TextField.getText());
        currentStory.setAsA(AsA_TextField.getText());
        currentStory.setIWant(IWant_TextArea.getText());
        currentStory.setSoThat(SoThat_TextArea.getText());
        currentStory.setEffort(Effort_TextField.getText());
        currentStory.setAssignee((String) Assignee_ComboBox.getSelectedItem());
        currentStory.setAttachment(Attachment_TextField.getText());
        clearStory();
        // Extract the Story Titles into an array for display.
        ArrayList<String> stringList = new ArrayList();
        for (Story story : DevManagerView.getCurrentProject().getStories()) {
            // NEED TO CALL A FORMATTER FUNCTION HERE
            stringList.add(story.getTitle() + " - " + story.getAssignee());
        }
        // Display the Story Titles list
        UserStories_List.setListData(stringList.toArray());
    }

    /**
     * @param
     */
    private void StoryCancel_ButtonMouseClicked(MouseEvent evt) {
        clearStory();
    }

    /**
     * @param
     */
    private void UserStoriesMoveUp_ButtonMouseClicked(MouseEvent evt) {
        // TODO Need parameter list defined:
        //   Project.moveUp();
    }

    /**
     * This function
     * @param
     */
    private void UserStoriesMoveDown_ButtonMouseClicked(MouseEvent evt) {
        // TODO Need parameter list defined:
        //    Project.moveDown();
    }

    /**
     * This function
     * @param
     */
    private void UserStoriesEdit_ButtonMouseClicked(MouseEvent evt) {
        // TODO add your handling code here:
    }

    /**
     * This function
     * @param
     */
    private void UserStoriesDelete_ButtonMouseClicked(java.awt.event.MouseEvent evt) {
        // TODO add your handling code here:
    }

    /**
     * This function
     * @param
     */
    private void AttachmentBrowse_ButtonActionPerformed(ActionEvent evt) {
        if (Attachment_TextField.getText().equals(""))
        {
            final JFileChooser fc = new JFileChooser();
            int returnVal = fc.showOpenDialog(this);
            if(returnVal == JFileChooser.APPROVE_OPTION)
            {
                Attachment_TextField.setText(fc.getCurrentDirectory() + fc.getSelectedFile().getName());
            }
        } else {
            final JFileChooser fc = new JFileChooser(Attachment_TextField.getText());
            int returnVal = fc.showOpenDialog(this);
            if(returnVal == JFileChooser.APPROVE_OPTION)
            {
                Attachment_TextField.setText(fc.getCurrentDirectory() + "\\" + fc.getSelectedFile().getName());
            }
        }
    }

    /**
     * This function
     * @param
     */
    private void AgileRequirementsOK_ButtonActionPerformed(ActionEvent evt) {
        // TODO add your handling code here:
        doClose(RET_OK);
    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton AgileRequirementsOK_Button;
    private javax.swing.JLabel AsA_Label;
    private javax.swing.JTextField AsA_TextField;
    private javax.swing.JLabel AssigneeUserStories_Label;
    private javax.swing.JComboBox Assignee_ComboBox;
    private javax.swing.JLabel Assignee_Label;
    private javax.swing.JButton AttachmentBrowse_Button;
    private javax.swing.JLabel Attachment_Label;
    private javax.swing.JTextField Attachment_TextField;
    private javax.swing.JLabel Effort_Label;
    private javax.swing.JTextField Effort_TextField;
    private javax.swing.JLabel IWant_Label;
    private javax.swing.JScrollPane IWant_ScrollPane;
    private javax.swing.JTextArea IWant_TextArea;
    private javax.swing.JPanel MainOK_Panel;
    private javax.swing.JLabel PercentComplete_Label;
    private javax.swing.JLabel SoThat_Label;
    private javax.swing.JScrollPane SoThat_ScrollPane;
    private javax.swing.JTextArea SoThat_TextArea;
    private javax.swing.JPanel StoryBase_Panel;
    private javax.swing.JPanel StoryButtons_Panel;
    private javax.swing.JButton StoryCancel_Button;
    private javax.swing.JButton StorySave_Button;
    private javax.swing.JLabel StoryTitile_Label;
    private javax.swing.JPanel Story_Panel;
    private javax.swing.JLabel Title_Label;
    private javax.swing.JTextField Title_TextField;
    private javax.swing.JPanel UserStoriesButtons_Panel;
    private javax.swing.JButton UserStoriesDelete_Button;
    private javax.swing.JButton UserStoriesEdit_Button;
    private javax.swing.JButton UserStoriesMoveDown_Button;
    private javax.swing.JButton UserStoriesMoveUp_Button;
    private javax.swing.JList UserStories_List;
    private javax.swing.JPanel UserStories_Panel;
    private javax.swing.JScrollPane UserStories_ScrollPane;
    // End of variables declaration//GEN-END:variables

    private int returnStatus = RET_CANCEL;
}
